package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 1:38:19 PM
 */
public class XorWF extends InstructionSupport {
    private static final Log log = LogFactory.getLog(XorWF.class);

    public XorWF(final boolean targetIsWRegister, final Bits argument) {
        super(targetIsWRegister, true, argument);
    }

    @NotNull
    @Override
    protected RegisterValue getValue(@NotNull final RegisterValue addressedFile, @NotNull final RegisterValue wRegister,
                                     @NotNull final List<PicAction> yourActions,
                                     @NotNull final ActionFactory actionFactory) {
        log.debug("IorWF gets executed");
        final int wFile = wRegister.asInteger();
        final int addressedValue = addressedFile.asInteger();
        final int result = wFile ^ addressedValue;


        log.debug("result is " + result);
        return RegisterValueImpl.createUnsafe(result);
    }
}
